//Thursday, November 05 2009
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

template<class T> inline void checkmax(T &a,T b){if(b>a) a=b;}
#define 	inf 	100000001
class HamiltonPath
{
public:
	int N;
	vector<bool> visit;
	vector<int> d;
	int countPaths(vector <string> roads)
	{
		N = roads.size();
		for(int i=0; i<N; i++)
		{
			visit.push_back(false);
			d.push_back(0);
		}
		for (int i=0;i<N;i++)
		{
			int s=0;
			for (int j=0;j<N;j++)
				if (roads[i][j]=='Y') s++;
			if (s>2) return 0;
			d[i]=s;
		}
		int tot1=0,tot2=0;
		for (int i=0;i<N;i++)
			if ((!visit[i])&&(d[i]<2))
			{
				dfs(i, roads);
				if (d[i]==0) tot1++;
				else tot2++;
			}
		for (int i=0;i<N;i++)
			if (!visit[i])
				return 0;
		long long ans=1;
		for (long long i=0;i<tot1+tot2;i++) ans=(ans*(i+1)) % 1000000007;
		for (int i=0;i<tot2;i++)
			ans=(ans*2) % 1000000007;
		return ans;
	}
	void dfs(int now, vector<string> roads)
	{
		visit[now]=true;
		for (int i=0;i<N;i++)
			if ((roads[now][i]=='Y')&&(!visit[i]))
				dfs(i, roads);
		//visit[now] = false;
	}
};